﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kendo.Mvc.UI;
using Library.AppWeb;
using Kendo.Mvc.Extensions;
using MPR.Poker.Model.LIS;

namespace PokerLife.Controllers.LIS
{
    public class CountryController : Controller
    {
        //
        // GET: /Country/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public ActionResult AddEdit()
        {           
            return View();
        }

        public ActionResult Country_Load([DataSourceRequest] DataSourceRequest request)
        {
            List<MPR.Poker.Model.LIS.LIS_Country> lst = new List<MPR.Poker.Model.LIS.LIS_Country>();
            ResultMessage result = new MPR.Poker.DALEntity.LIS.DAL_Country().SelectToList(ref lst);
            return Json(lst.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }

        public ActionResult AddEdit(int intIDSys = 0)
        {
            PokerLife.Models.LIS.CountryViewModel model = new PokerLife.Models.LIS.CountryViewModel();

            if (intIDSys > 0)
            {
                MPR.Poker.Model.LIS.LIS_Country obj = new MPR.Poker.Model.LIS.LIS_Country();
                ResultMessage result = new MPR.Poker.DALEntity.LIS.DAL_Country().LoadInfo(ref obj, intIDSys);
                if (!result.IsError)
                    model = PokerLife.Models.LIS.CountryViewModel.ConvertToModel(obj);
            }

            return View(model);
        }

        [HttpPost]
        public ActionResult AddEdit(PokerLife.Models.LIS.CountryViewModel Country)
        {
            MPR.Poker.Model.LIS.LIS_Country objCountry = new MPR.Poker.Model.LIS.LIS_Country();
            objCountry = PokerLife.Models.LIS.CountryViewModel.ConvertTo(Country);

            ResultMessage result = new ResultMessage();
            if (objCountry.IDSys > 0)
                result = new MPR.Poker.DALEntity.LIS.DAL_Country().Update(objCountry);
            else
                result = new MPR.Poker.DALEntity.LIS.DAL_Country().Insert(objCountry);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Delete(int intIDSys)
        {
            ResultMessage result = new ResultMessage();
            result = new MPR.Poker.DALEntity.LIS.DAL_Country().Delete (intIDSys, 1);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult DeleteList(int[] lstIDSys)
        {
            ResultMessage result = new ResultMessage();
            result = new MPR.Poker.DALEntity.LIS.DAL_Country().Delete(lstIDSys.ToList(), 1);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
}
